package cn.uc.bs;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;
import java.util.Vector;

import cn.uc.db.BaseObject;

public class DiaryObejct /*extends BaseObject*/{
    private String id;//uuid
    private String iTitle = "Unnaming";
    private long iTimeMills;
    private ArrayList<ContentObject> iContents = new ArrayList<ContentObject>();
    private String iText;
    
    private static HashMap<String, String> gAttrbutes = new HashMap<String, String>();
    
    public DiaryObejct(String aTitle){
        this.id = UUID.randomUUID().toString();
        iTitle = aTitle; 
        iTimeMills = System.currentTimeMillis();
     
    }
    
    public DiaryObejct(){
        
    }
    
    public void setId(String aId){
        id = aId;
    }
    
    public String getId() {
        return id;
    }
    
    public String getDateTime(){
        Date sDate = new Date(iTimeMills); 
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
        String str = format.format(sDate);
        return str;
    }
    
    public Date getDate(){        
        return new Date(iTimeMills);
    }
    
    public long getTimeMills(){
        return iTimeMills;
    }
    
    public void setTimeMills(long aTimeMills){
        iTimeMills = aTimeMills;
    }
    
    public String getTitle() {
        return iTitle;
    }
    
    public void setTitle(String aTitle) {
        this.iTitle = aTitle;
    }
    
    public ArrayList<ContentObject> getContents() {
        return iContents;
    }
    
    public String getContentsString(){
        StringBuffer sContent = new StringBuffer();
        for(int i = 0; i < iContents.size(); i++){
            sContent.append(iContents.get(i).getId());
            if(i < iContents.size() -1){
                sContent.append(";");
            }
        }
        return sContent.toString();
    }
    
    public void setContents(ArrayList<ContentObject> aContents) {
        this.iContents = aContents;
    }
    
    public void setContent(String acontent){
        iText = acontent;
    }
    
    public String getContent(){
        return iText;
    }

    
    public void addConent(ContentObject aContentObject){
        aContentObject.setParentId(id);
        iContents.add(aContentObject);
    }


 //   @Override
    public static String attribute2String(String attribute) {
        // XXX Auto-generated method stub
        if(gAttrbutes.isEmpty()){
            gAttrbutes.put("id", "INTEGER PRIMARY KEY AUTOINCREMENT");
            gAttrbutes.put("title", "varchar(64)");
            gAttrbutes.put("date", "INTEGER");
        }
        
        return gAttrbutes.get(attribute);
    }
    

}
